package ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.model;

import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.enums.SaveContextActionEnum;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

/**
 * .
 * @author Caspar
 *
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class SaveContext<T> {

  /**
   * 保存的数据
   */
  private T data;
  /**
   * 新增或修改
   */
  private SaveContextActionEnum action;

  /**
   * data是否为null.
   * @return true / false
   */
  public boolean isNull() {
    return Objects.isNull(data);
  }


  public boolean isNew() {
    return SaveContextActionEnum.ADD.equals(this.action);
  }

  public boolean isModify() {
    return SaveContextActionEnum.MODIFY.equals(this.action);
  }

  public boolean isRemove() {
    return SaveContextActionEnum.REMOVE.equals(this.action);
  }
}
